import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image } from "@tarojs/components-rn";
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, phoneNumPartOf } from "../../utils/common";
import settingStyleSheet from "./setting_styles";

import right from "../../assets/img/right.png";
var _styleSheet = settingStyleSheet;
let Index = class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userInfo: {}
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '设置' });
    let userInfo = getRuntime().getUserInfo();
    if (userInfo) {
      this.setState({
        userInfo
      });
    }
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  // 退出登录
  logout() {
    let { userStore } = this.props.stores;
    userStore.logout({
      callback: () => {
        Taro.removeStorageSync('user');
        getRuntime().showToast('退出登录成功~');
        setTimeout(() => {
          getRuntime().navigateTo('/pages/index/index');
        }, 1000);
      }
    });
  }
  render() {
    let { userInfo } = this.state;
    return <View style={[_styleSheet["my-my"], _styleSheet["setting"]]}>
        <View style={[_styleSheet["wrap-box"], _styleSheet["my-from"]]}>
          <View style={_styleSheet["item-group"]}>
            <View onClick={this.handelRouter.bind(this, '/pages/user/user_info_edit')} style={_styleSheet["line"]}>
              <View style={_styleSheet["list-title"]}>个人资料</View>
              <View style={_styleSheet["list-desc"]}>
                <Image src={right} style={[_styleSheet["img"], _styleSheet["icon-drop-down"]]} />
              </View>
            </View>

            <View onClick={this.handelRouter.bind(this, '/pages/user/address')} style={_styleSheet["line"]}>
              <View style={_styleSheet["list-title"]}>收货地址</View>
              <View style={_styleSheet["list-desc"]}>
                <Image src={right} style={[_styleSheet["img"], _styleSheet["icon-drop-down"]]} />
              </View>
            </View>
          </View>
        </View>

        <View style={[_styleSheet["wrap-box"], _styleSheet["my-from"]]}>

          <View style={_styleSheet["item-group"]}>
            
            <View style={_styleSheet["line"]}>
              <View style={_styleSheet["list-title"]}>手机号</View>
              <View style={_styleSheet["list-desc"]}>{phoneNumPartOf(userInfo.phoneNumber)}
                <Image src={right} style={[_styleSheet["img"], _styleSheet["icon-drop-down"]]} />
              </View>
            </View>

            <View onClick={this.handelRouter.bind(this, '/pages/user/set_password')} style={_styleSheet["line"]}>
              <View style={_styleSheet["list-title"]}>密码修改</View>
              <View style={_styleSheet["list-desc"]}>
                <Image src={right} style={[_styleSheet["img"], _styleSheet["icon-drop-down"]]} />
              </View>
            </View>
          </View>

          <View style={_styleSheet["item-group"]}>
            <View onClick={this.handelRouter.bind(this, '/pages/user/about')} style={_styleSheet["line"]}>
              <View style={_styleSheet["list-title"]}>关于我们</View>
              <View style={_styleSheet["list-desc"]}>查看
                <Image src={right} style={[_styleSheet["img"], _styleSheet["icon-drop-down"]]} />
              </View>
            </View>
          </View>

          <View style={_styleSheet["item-group"]}>
            <View style={_styleSheet["line"]}>
              <View onClick={this.logout.bind(this)} style={[_styleSheet["list-title"], _styleSheet["color-light"]]}>退出登录</View>
            </View>
          </View>
        </View>

      </View>;
  }
};
Index = tslib_1.__decorate([inject("stores"), observer], Index);
export default Index;